package cn.iocoder.yudao.module.fengdong.smartelderly.dal.mysql.oldman;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.fengdong.smartelderly.dal.dataobject.oldman.OldmanDO;
import cn.iocoder.yudao.module.fengdong.smartelderly.utils.vo.ActivityRecordBaseVO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.fengdong.smartelderly.controller.admin.oldman.vo.*;
import org.apache.ibatis.annotations.Param;

/**
 * 老人管理 Mapper
 *
 * @author 沣东养老院管理员
 */
@Mapper
public interface OldmanMapper extends BaseMapperX<OldmanDO> {

    default PageResult<OldmanDO> selectPage(OldmanPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<OldmanDO>()
                .likeIfPresent(OldmanDO::getName, reqVO.getName())
                .eqIfPresent(OldmanDO::getIdentityCard, reqVO.getIdentityCard())
                .eqIfPresent(OldmanDO::getPhoneNumber, reqVO.getPhoneNumber())
                .eqIfPresent(OldmanDO::getGuardianName, reqVO.getGuardianName())
                .eqIfPresent(OldmanDO::getGuardianCard, reqVO.getGuardianCard())
                .eqIfPresent(OldmanDO::getGuardianNumber, reqVO.getGuardianNumber())
                .eqIfPresent(OldmanDO::getAge, reqVO.getAge())
                .eqIfPresent(OldmanDO::getRoomId, reqVO.getRoomId())
                .eqIfPresent(OldmanDO::getQrUrl, reqVO.getQrUrl())
                .betweenIfPresent(OldmanDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(OldmanDO::getSex, reqVO.getSex())
                .eqIfPresent(OldmanDO::getType, reqVO.getType())
                .orderByDesc(OldmanDO::getId));
    }

    default List<OldmanDO> selectList(OldmanExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<OldmanDO>()
                .likeIfPresent(OldmanDO::getName, reqVO.getName())
                .eqIfPresent(OldmanDO::getIdentityCard, reqVO.getIdentityCard())
                .eqIfPresent(OldmanDO::getPhoneNumber, reqVO.getPhoneNumber())
                .eqIfPresent(OldmanDO::getAge, reqVO.getAge())
                .eqIfPresent(OldmanDO::getGuardianName, reqVO.getGuardianName())
                .eqIfPresent(OldmanDO::getGuardianCard, reqVO.getGuardianCard())
                .eqIfPresent(OldmanDO::getGuardianNumber, reqVO.getGuardianNumber())
                .eqIfPresent(OldmanDO::getRoomId, reqVO.getRoomId())
                .eqIfPresent(OldmanDO::getQrUrl, reqVO.getQrUrl())
                .betweenIfPresent(OldmanDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(OldmanDO::getSex, reqVO.getSex())
                .eqIfPresent(OldmanDO::getType, reqVO.getType())
                .orderByDesc(OldmanDO::getId));
    }

    List<OldmanDO> selectListByTenantId(@Param("tenantId") Long tenantId);

    default OldmanDO selectCountByCardANDPhone(OldmanDO reqVO) {
        return selectOne(new LambdaQueryWrapperX<OldmanDO>()
                .or(wrapper -> wrapper.eq(OldmanDO::getIdentityCard, reqVO.getIdentityCard())
                        .or(wrapperT -> wrapperT.eq(OldmanDO::getPhoneNumber, reqVO.getPhoneNumber()))));
    }

    default OldmanDO selectOldManByIdentityCard(OldmanImportExcelVO reqVO){
        return selectOne(new LambdaQueryWrapperX<OldmanDO>()
                .or(wrapper -> wrapper.eq(OldmanDO::getIdentityCard, reqVO.getIdentityCard())
                        .or(wrapperT -> wrapperT.eq(OldmanDO::getPhoneNumber, reqVO.getPhoneNumber()))));
    }

    List<OldmanDO> selectOldmanExBytype(@Param("param") ActivityRecordBaseVO recordBaseVO);

    List<OldmanDO> selectFkExBytype(ActivityRecordBaseVO recordBaseVO);
}
